using MicroMsg.Plugin;
using MicroMsg.Resource.@string;
using MicroMsg.UI.UserContrl;
using MicroMsg.UI.Util;
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace MicroMsg.UI.Page
{
	public class PluginSettingPage : BasePage
	{
		private PluginBase mPlugin;
		private string mPluginName;
		private PluginSettingBaseCtrl mPluginSetCtrl;
		internal Grid LayoutRoot;
		internal StackPanel ContentPanel;
		internal Image ImgPlugin;
		internal ScrollTextBlock txtPluginName;
		internal Image icon_Installed;
		internal Image icon_Uninstall;
		internal TextBlock txtIsInstalled;
		internal TextBlock txtPluginDetail;
		internal StackPanel panelPluginCtrl;
		internal Button btnInstall_Or_Uninstall;
		private bool _contentLoaded;
		public PluginSettingPage()
		{
			this.InitializeComponent();
			base.add_Loaded(new RoutedEventHandler(this.Page_Loaded));
			base.add_Unloaded(new RoutedEventHandler(this.Page_Unloaded));
		}
		private void Page_Loaded(object sender, RoutedEventArgs e)
		{
			this.ContentPanel.set_Visibility(0);
		}
		private void Page_Unloaded(object sender, RoutedEventArgs e)
		{
		}
		protected override void OnPageIn(object[] object_0)
		{
			if (object_0 != null && object_0.Length != 0 && object_0[0] is PluginBase)
			{
				this.mPlugin = (object_0[0] as PluginBase);
				this.mPluginName = this.mPlugin.mName;
				this.initUI();
				return;
			}
			base.GoBack();
		}
		protected override void OnPageOut()
		{
			if (this.mPluginSetCtrl != null)
			{
				this.mPluginSetCtrl.Exit();
			}
		}
		protected override void OnPageBack()
		{
		}
		private void initUI()
		{
			this.refreshView();
		}
		private void refreshView()
		{
			if (this.mPlugin.isInstalledPlugin())
			{
				this.panelPluginCtrl.set_Visibility(0);
				this.panelPluginCtrl.get_Children().Clear();
				this.mPluginSetCtrl = this.mPlugin.GetPluginSettingCtrl();
				if (this.mPluginSetCtrl != null)
				{
					this.panelPluginCtrl.get_Children().Add(this.mPluginSetCtrl);
				}
			}
			else
			{
				this.panelPluginCtrl.set_Visibility(1);
			}
			this.ImgPlugin.set_Source(this.mPlugin.mIcon);
			this.txtPluginDetail.set_Text(this.mPlugin.mDescription);
			this.txtPluginName.Text = this.mPlugin.mTitle;
			if (this.mPlugin.isInstalledPlugin())
			{
				this.btnInstall_Or_Uninstall.set_Content(strings.Set_Plugin_DoUnInstall);
				this.btnInstall_Or_Uninstall.set_Style(R.theme.UnInstallButtonStyle);
				this.txtIsInstalled.set_Text(strings.Set_Plugin_Installed);
				this.txtIsInstalled.set_Foreground(R.theme.COMMON_BRUSH);
				this.icon_Installed.set_Visibility(0);
				this.icon_Uninstall.set_Visibility(1);
				return;
			}
			this.btnInstall_Or_Uninstall.set_Content(strings.Set_Plugin_DoInstall);
			this.btnInstall_Or_Uninstall.set_Style(R.theme.MMButtonWithoutMargin);
			this.txtIsInstalled.set_Text(strings.Set_Plugin_UnInstall);
			this.txtIsInstalled.set_Foreground(R.theme.SETTING_SEPARATE_LINE_BRUSH);
			this.icon_Installed.set_Visibility(1);
			this.icon_Uninstall.set_Visibility(0);
		}
		public string GetPluginName()
		{
			if (this.mPlugin == null)
			{
				return "";
			}
			return this.mPlugin.mName;
		}
		private void btnButton_Click(object sender, RoutedEventArgs e)
		{
			if (this.mPlugin.isInstalledPlugin())
			{
				MMMessageBox mMMessageBox = MMMessageBox.Show("", strings.Set_Plugin_UnInstall_ClearData, true, strings.Set_Plugin_Plugin_ClearData, strings.COM_Cancel);
				mMMessageBox.set_FontSize(22.0);
				mMMessageBox.ReturnEvent = new DlgReturnEvent(this.MsgBoxClearDataHandler);
				return;
			}
			this.showProgressCover(strings.Set_Plugin_Installing);
			base.get_Dispatcher().BeginInvoke(delegate
			{
				this.doInstall();
				this.hideProgressCover();
			});
		}
		public void MsgBoxClearDataHandler(DlgReturnEventArg dlgReturnEventArg_0)
		{
			switch (MMMessageBox.GetUserClickResult(dlgReturnEventArg_0))
			{
			case 0:
				this.showProgressCover(strings.Set_Plugin_UnInstalling);
				base.get_Dispatcher().BeginInvoke(delegate
				{
					this.doUninstall();
					this.hideProgressCover();
				});
				break;
			case 1:
				break;
			default:
				return;
			}
		}
		private void doUninstall()
		{
			if (this.mPlugin != null && ExtentCenter.uninstallPlugin(this.mPlugin, InstallMode.UserInstall))
			{
				this.mPlugin = PluginManager.findPluginByName(this.mPluginName);
				this.refreshView();
			}
		}
		private void doInstall()
		{
			if (this.mPlugin != null && ExtentCenter.installPlugin(this.mPlugin, InstallMode.UserInstall))
			{
				this.mPlugin = PluginManager.findPluginByName(this.mPluginName);
				this.refreshView();
			}
		}
		private void showProgressCover(string strCoverTitle)
		{
			ProcessingCover.getProgressBar(this.LayoutRoot, strCoverTitle, (SolidColorBrush)Application.get_Current().get_Resources().get_Item("HalfOpacityBrush1"), false, false, null);
		}
		private void hideProgressCover()
		{
			ProcessingCover.releaseProgressBar(this.LayoutRoot);
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/Plugin/PluginSettingPage.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.ContentPanel = (StackPanel)base.FindName("ContentPanel");
			this.ImgPlugin = (Image)base.FindName("ImgPlugin");
			this.txtPluginName = (ScrollTextBlock)base.FindName("txtPluginName");
			this.icon_Installed = (Image)base.FindName("icon_Installed");
			this.icon_Uninstall = (Image)base.FindName("icon_Uninstall");
			this.txtIsInstalled = (TextBlock)base.FindName("txtIsInstalled");
			this.txtPluginDetail = (TextBlock)base.FindName("txtPluginDetail");
			this.panelPluginCtrl = (StackPanel)base.FindName("panelPluginCtrl");
			this.btnInstall_Or_Uninstall = (Button)base.FindName("btnInstall_Or_Uninstall");
		}
	}
}
